// pages/myCommission/myCommission.js
const app = getApp();
var util = require('../../utils/util.js');
Page({
  data: {
    crusrTotalIncome: "",//累计佣金总额
    crusrWeekIncome: "",//本周佣金总额
    crusrFrozenIncome: "",//冻结佣金总额
    crusrEnableIncome: "",//解冻佣金总额
    modal: {
      toastHidden: true,
      msg: "当前网格异常，请稍后再试"
    },
    card: [
      {
        name: "张帅",
        date: "2017-12-28",
        money: "￥5000.00",
        coupon: "￥300.00"
      }],
    pageNum: 1,
    pageSize: 10
  },
  onLoad: function (options) {
    var that = this;
    let data1 = {
      crusrUuid: app.globalData.userUuid
    }
    util.requestGet("coreUser/views", data1, function (res) {
      if (res.success) {
        console.log(res)
        that.setData({ "crusrTotalIncome": res.data.crusrTotalIncome });
        that.setData({ "crusrWeekIncome": res.data.crusrWeekIncome });
        that.setData({ "crusrFrozenIncome": res.data.crusrFrozenIncome });
        that.setData({ "crusrEnableIncome": res.data.crusrEnableIncome });

      } else {
        //  console.log(res)
      }

    }, function (errData) {
      util.tipModal(that, "获取失败！");
    });

    var data = {
      crcrdBeUser: app.globalData.userUuid,
      pageNum: that.data.pageNum,
      pageSize: that.data.pageSize
    };
    util.requestGet("coreCommissionRecord/find/my/page", data, function (res) {
      if (res.success) {
        var new_card = [];
        var obj = {};
        for (var i = 0; i < res.data.result.length; i++) {
          var obj = {};
          obj.money = res.data.result[i].crcrdBeFee;
          obj.name = res.data.result[i].crcrdUserName;
          obj.coupon = res.data.result[i].crcrdBeFee;
          obj.money = res.data.result[i].crcrdFee;

          obj.date = new Date(res.data.result[i].crcrdDate).toLocaleDateString().substr(5);
          new_card.push(obj);
        }
        that.setData({ "card": new_card });
      } else {
        //  console.log(res)
      }

    }, function (errData) {
      util.tipModal(that, "获取失败！");
    });

  },
  onReady: function () {

  },
  onShow: function () {
  },
  onHide: function () {

  },
  onUnload: function () {

  },
  toastChange() {
    this.setData({
      duration: e.detail.value
    })
  }
})